/**
 * @author: Loy-winters1224@163.com
 * @date: 2014-8-21-下午6:26:37
 */
package net.loyintean.pearlshell.wechat.service.encrypt;

import net.loyintean.pearlshell.wechat.model.BaseMessageModel;
import net.loyintean.pearlshell.wechat.model.common.TextMessageModel;
import net.loyintean.pearlshell.wechat.service.DefaultMessageProcesser;
import net.loyintean.pearlshell.wechat.util.EncrAESUtil;

/**
 * 
 * @author Loy-winters1224@163.com
 * @version 2014-8-21.1.0.0
 */
public class EncryptMessageProcesser extends DefaultMessageProcesser {

	/**
	 * encrypt the
	 * 
	 * @author Loy-winters1224@163.com
	 * @see net.loyintean.pearlshell.wechat.service.DefaultMessageProcesser
	 *      #getContent(net.loyintean.pearlshell.wechat.model.BaseMessageModel)
	 * 
	 */
	@Override
	protected String getContent(BaseMessageModel request) {
		assert request != null;

		String encryptContent = super.getContent(request);

		if (request instanceof TextMessageModel) {
			TextMessageModel textMessage = (TextMessageModel) request;

			String content = textMessage.getContent().substring(3);

			String fromUser = textMessage.getFromUserName();

			encryptContent = EncrAESUtil.encrypt(content, fromUser);
		}

		return encryptContent;
	}
}
